package com.kmproject.haifu.mvp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hwy.swipelistviewlibrary.adapter.SwipeAdapter;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NyCollectHouseRentAdapter_bat extends SwipeAdapter<HouseRentListShowInfoBean> {
    List<HouseRentListShowInfoBean> mdata;

    public NyCollectHouseRentAdapter_bat(Context context, List<HouseRentListShowInfoBean> data) {
        super(context, data);
        this.mdata = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.house_me_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        // 初始化相关的监听
        init(convertView, position);
        removeAllMenu(convertView);
        addMenuView(convertView, createView());

        return convertView;
    }

    /**
     * 刷新数据
     */
    public void refershData(List<HouseRentListShowInfoBean> houseRentListShowInfoBeans) {
        mdata.clear();
        if (houseRentListShowInfoBeans != null && !houseRentListShowInfoBeans.isEmpty()) {
            mdata.addAll(houseRentListShowInfoBeans);
        }
        notifyDataSetChanged();
    }

    private View createView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.collect_item_checkbox, null);
        CheckBox checkBox = view.findViewById(R.id.collect_item_checkbox);
        return checkBox;
    }

    static class ViewHolder {
        @BindView(R.id.houserenting_main_content_item_img)
        ImageView houserentingMainContentItemImg;
        @BindView(R.id.houserenting_main_content_item_txt1)
        TextView houserentingMainContentItemTxt1;
        @BindView(R.id.houserenting_main_content_item_txt2)
        TextView houserentingMainContentItemTxt2;
        @BindView(R.id.houserenting_main_content_item_txt4)
        TextView houserentingMainContentItemTxt4;
        @BindView(R.id.houserenting_main_content_item_txt5)
        TextView houserentingMainContentItemTxt5;
        @BindView(R.id.houseRentingShow_item_lay)
        LinearLayout houseRentingShowItemLay;
        @BindView(R.id.houseRentingShow_item_selectImg)
        ImageView houseRentingShowItemSelectImg;

        public ViewHolder(View view) {
//            R.layout.house_me_list_item
            ButterKnife.bind(this, view);
        }
    }
}
